<?php

session_start(); 
$username=$_SESSION['username'];
//$username='gip2103';
//$username = $_POST['cuid'];
$user = $_POST['cuidrec'];
$pic = $_POST['empphoto'];
//$user='xw2174';


//echo 'Message'.$username.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber;

/*$username='jhg1234';
//$username = $_POST['cuid'];
$address1 = 'pppp';
$address2 = 'pppp';
$city = 'pppp';
$state = 'pppp';
$country = 'pppp';
$zipcode = '12345';
$cellnumber = '1234567899';*/

$conn = oci_connect("gaurav", "gaurav", "xe"); 
$stmt = "UPDATE Candidate SET SelfImage = :photo"; 
 
$bindargs1 = array();
array_push($bindargs1, array('PHOTO', $pic, 10));


 
$r = db_execute_statement($conn, $stmt, $bindargs1);


function db_insert_thumbnail($conn, $empid, $imgfile, &$e)
{
  $lob = oci_new_descriptor($conn, OCI_D_LOB);
  if (!$lob) {
    $e = db_error($conn, __FILE__, __LINE__);
    return false;
  }

  $insstmt =
    'INSERT INTO employee_photos (employee_id, employee_thumbnail)
     VALUES(:eid, empty_blob())
     RETURNING employee_thumbnail into :etn';

  $stmt = oci_parse($conn, $insstmt);
  $r = oci_bind_by_name($stmt, ':etn', $lob, -1, OCI_B_BLOB);
  if (!$r) {
    $e = db_error($stid, __FILE__, __LINE__);
    return false;
  }
  $r = oci_bind_by_name($stmt, ':eid', $empid, -1);
  if (!$r) {
    $e = db_error($stid, __FILE__, __LINE__);
    return false;
  }
  $r = oci_execute($stmt, OCI_DEFAULT);
  if (!$r) {
    $e = db_error($stid, __FILE__, __LINE__);
    return false;
  }

  if (!$lob->savefile($imgfile)) {
    $e = db_error($stid, __FILE__, __LINE__);
    return false;
  }
  $lob->free();

  return true;
}





function db_execute_statement($conn, $statement, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  return($r);
}

?>